package com.dhcc.sds.base.controller;


import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;



import com.dhcc.sds.base.entity.SdsQcentityIndexAliasEntity;
import com.dhcc.sds.base.service.ISdsQcentityIndexAliasService;


/**
 * 指标项明细(待定)
 * 
 * @ClassName: SdsQcentityIndexAliasController
 * @Description: TODO
 * @author sunyingjie
 * @date 2021-03-22 10:10:51
 */
@Controller
@RequestMapping("${sys.backendPath}/sds/sdsqcentityindexalias")
public class SdsQcentityIndexAliasController extends BaseController {

	private String PREFIX = "/backend/sds/sdsqcentityindexalias/";

	@Autowired
	private ISdsQcentityIndexAliasService sdsQcentityIndexAliasService;
	

    /**
     * 跳转到指标项明细(待定)列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sdsqcentityindexalias.html";
    }
	
    /**
     * 跳转到新增指标项明细(待定)
     */
    @RequestMapping("/to_add")
    public String toAdd() {
        return PREFIX + "sdsqcentityindexalias_add.html";
    }
	
	/**
     * 跳转到修改指标项明细(待定)
     */
    @RequestMapping("/to_update/{sdsQcentityIndexAliasId}")
    public String toUpdate(@PathVariable Long sdsQcentityIndexAliasId, Model model) {
        SdsQcentityIndexAliasEntity sdsQcentityIndexAlias = this.sdsQcentityIndexAliasService.selectById(sdsQcentityIndexAliasId);
        model.addAttribute("sdsQcentityIndexAlias",sdsQcentityIndexAlias);
        return PREFIX + "sdsqcentityindexalias_edit.html";
    }

    /**
     * 获取指标项明细(待定)列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
		Page<SdsQcentityIndexAliasEntity> page = new PageFactory<SdsQcentityIndexAliasEntity>().defaultPage();
        List<SdsQcentityIndexAliasEntity> result = this.sdsQcentityIndexAliasService.page(page,params);
        page.setRecords((List<SdsQcentityIndexAliasEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增指标项明细(待定)
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SdsQcentityIndexAliasEntity sdsQcentityIndexAlias) {
        if (CommonUtil.isOneEmpty(sdsQcentityIndexAlias)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        sdsQcentityIndexAlias.insert();
        return R.ok();
    }

    /**
     * 删除指标项明细(待定)
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long sdsQcentityIndexAliasId) {
	
        this.sdsQcentityIndexAliasService.deleteById(sdsQcentityIndexAliasId);

        return R.ok();
    }

    /**
     * 修改指标项明细(待定)
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SdsQcentityIndexAliasEntity sdsQcentityIndexAlias) {
        if (CommonUtil.isOneEmpty(sdsQcentityIndexAlias)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        SdsQcentityIndexAliasEntity old = this.sdsQcentityIndexAliasService.selectById(sdsQcentityIndexAlias.getId());

        old.setParref(sdsQcentityIndexAlias.getParref());
        old.setSubIdxDesc(sdsQcentityIndexAlias.getSubIdxDesc());
        old.setStaType(sdsQcentityIndexAlias.getStaType());
        old.setEntityItemDr(sdsQcentityIndexAlias.getEntityItemDr());
        old.setCalcExpress(sdsQcentityIndexAlias.getCalcExpress());
        old.setIndNo(sdsQcentityIndexAlias.getIndNo());
        old.setIsActive(sdsQcentityIndexAlias.getIsActive());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
